home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / c_src2_5.zoo / init.c < prev    next >
C/C++ Source or Header  |  1989-08-16  |  6KB  |  213 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25. /* init.c */
  26.  
  27. /* modification history --------------------------------------------
  28.     07/16/89 - RNK - Use <string.h> instead of <strings.h> when AMIGA
  29.                is defined.
  30.  
  31. RNK = Nick Kline
  32. *******************************/
  33.  
  34. #include "sim.h"
  35. #include "inst.h"
  36. #include "aux.h"
  37. #ifndef AMIGA
  38. #include <strings.h>
  39. #endif
  40.  
  41. int maxmem = 100000;  /* 100000 */
  42. int maxpspace = 75000;
  43. int maxtrail;
  44.  
  45. int d_trace;
  46. int d_hitrace;
  47.  
  48. extern char *malloc();
  49.  
  50. /****************************************************************************/
  51.  
  52. init_sim(argc, argv)
  53. int argc;
  54. char *argv[];
  55. {
  56.    int i, itmp, tempint;
  57.    char perm = PERM;
  58.    word *insert(), *temp;
  59.    char c, *charp;
  60.  
  61. /* for debugging malloc on sun (include /usr/lib/debug/malloc.o in link) 
  62.     malloc_debug(2); */
  63.  
  64.    for ( i = 0; i < bucket_chain; i++ ) {
  65.     temp = (word *)&hash_table[i][TEMP]; make_free(*temp);
  66.     temp = (word *)&hash_table[i][PERM]; make_free(*temp);
  67.     }
  68.    trace = hitrace = disassem = num_line = trace_sta =
  69.         d_trace = d_hitrace = call_intercept = 0;
  70.    interrupt_code = 0;
  71.  
  72.    maxtrail = maxmem / 5;
  73.  
  74.    if (argc == 1) quit("Usage: sbprolog [-Ttdns] [-m s_size] [-p p_size] [-b tr_size] [-ui num] bytecode_file_name ...\n");
  75.    for (i=1; i<argc; i++) {
  76.         if (*argv[i] == '-') {
  77.            charp = argv[i];
  78.            while (c = *++charp) {
  79.                 switch(c) {
  80.                     case 't': trace = d_trace = 1;
  81.                       break;
  82.                     case 'T': hitrace = d_hitrace = 1;
  83.             case 's': trace_sta = 1;
  84.                   call_intercept = 1;
  85.                               break;
  86.                     case 'n': num_line = 1;
  87.                   break;
  88.                     case 'd': disassem = 1;
  89.                               break;
  90.                     case 'm': i++;
  91.                       sscanf(argv[i], "%d", &maxmem);
  92.                   maxtrail = maxmem / 5;
  93.                   break;
  94.             case 'p': i++;
  95.                       sscanf(argv[i], "%d", &maxpspace);
  96.                   break;
  97.             case 'b': i++;
  98.                       sscanf(argv[i], "%d", &maxtrail);
  99.                   break;
  100.             case 'u': i++; /* skip user field on this pass */
  101.                   charp++;
  102.                   break;
  103.             default : printf("Unknown option %c\n", c);
  104.                  }
  105.           } 
  106.     }
  107.    } /* for */
  108.  
  109.    pspace = (pw) (malloc(maxpspace*sizeof(word)));
  110.    if (!pspace) quit("Not enough core!\n");
  111.    max_fence = (byte *)(pspace+maxpspace);
  112.  
  113.    memory = (pw) (malloc(maxmem*sizeof(word)));
  114.    if (!memory) quit("Not enough core!\n");
  115.  
  116.    tstack = (pw) (malloc(maxtrail*sizeof(word)));
  117.    if (!tstack) quit("Not enough core!\n");
  118.    heap_bottom = memory;
  119.    local_bottom = memory + maxmem;
  120.    trail_bottom = tstack + maxtrail;
  121.  
  122.    breg = ereg = mlocaltop = local_bottom - 2;
  123.    hreg = mheaptop = heap_bottom;
  124.    trreg = mtrailtop = trail_bottom - 1;
  125.    hbreg = heap_bottom - 1;
  126.    curr_fence = (byte *)pspace;
  127.    *(curr_fence) = fail;
  128.    trap_vector[0] = curr_fence;
  129.    curr_fence += 2;
  130.    *(curr_fence) = halt; /* set halt instruction */
  131.    *(byte **)(local_bottom - 1) = curr_fence; /* halt on final failure */
  132.    cpreg = curr_fence; /* halt on final success */
  133.    curr_fence += 2;
  134.    temp = insert("[]", 2, 0, &perm);
  135.    nil_sym = (word)temp | CS_TAG;
  136.    temp = insert(".", 1, 2, &perm);
  137.    list_str = (word)temp | CS_TAG;
  138.    list_psc = (struct psc_rec *)follow(temp);
  139.    temp = insert(",", 1, 2, &perm);
  140.    comma_psc = (struct psc_rec *)follow(temp);
  141.    temp = insert("_$interrupt", 11, 2, &perm);
  142.    interrupt_psc = (struct psc_rec *)follow(temp);
  143.    trap_vector[1] = 0;
  144.    inst_begin = 0;
  145.  
  146.     /* now strip off user parameters */
  147.    for (i=0;i<10;i++) { flags[i] = nil_sym; }
  148.    for (i=1; i<argc; i++) {
  149.         if (*argv[i] == '-') {
  150.            charp = argv[i];
  151.  
  152.                   while (c = *++charp) {
  153.                 switch(c) {
  154.             case 'p': 
  155.             case 'b': 
  156.                     case 'm': i++;
  157.                     case 't': 
  158.                     case 'T': 
  159.             case 's': 
  160.                     case 'n': 
  161.                     case 'd': break;
  162.             case 'u': itmp = *++charp - '0'; 
  163.                   i++; /* value; retrieved by flags(index+10,V) */
  164.                   if (*argv[i]>=48 && *argv[i]<=57) { /*num*/
  165.                 sscanf(argv[i], "%d", &tempint);
  166.                 flags[itmp] = makeint(tempint);
  167.                   }
  168.                   else { /* make it a constant */
  169.                 temp = insert(argv[i], strlen(argv[i]), 
  170.                         0, &perm);
  171.                 flags[itmp] = (word)temp | CS_TAG;
  172.                   }
  173.                   break;
  174.                  }
  175.           } 
  176.     }
  177.    } /* for */
  178. }  /* init_sym */
  179.  
  180.  
  181.  
  182. /****************************************************************************/
  183.  
  184. init_loading(argc, argv)
  185.  
  186. int argc;
  187. char *argv[];
  188.  
  189. {
  190.    char c;
  191.    int i;
  192.    int n = 0; /* number of the initial loaded files */
  193.  
  194.    for (i=1; i<argc; i++) {
  195.         if (*argv[i] == '-') {
  196.        c = *(argv[i] + 1);
  197.            switch(c) {
  198.             case 'u': 
  199.             case 'm':
  200.             case 'p':
  201.             case 'b': i++;
  202.                     default : break;
  203.        }
  204.         }
  205.         else {
  206.         if (loader(argv[i])) quit("Error in loading initial files\n");
  207.         n++;
  208.     }
  209.      }  /* for */
  210.      if (n == 0) quit("No input file!\n");
  211. }  /* init_system */
  212.  
  213.